package com.ztgf.order.api.cms;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.utils.ExcelExport2;
import com.ztgf.order.models.bo.OrderCommissionStatisticsBO;
import com.ztgf.order.models.service.IOrderCommissionStatisticsService;
import com.ztgf.order.models.vo.OrderCommissionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/*
 * @author: chenyu.wang
 * @date: 2020-08-10
 * @description:后台管理系统佣金统计控制器
 */
@RestController
@RequestMapping("/cms/orderCommissionStatisticsController")
@Api(value = "OrderCommissionStatisticsController", tags = "后台管理系统佣金统计接口")
public class OrderCommissionStatisticsController {

    @DubboReference
    private IOrderCommissionStatisticsService iOrderCommissionStatisticsService;

    @PostMapping(value = "/queryCommissionStatistics")
    @ApiOperation(value = "佣金统计", notes = "佣金统计")
    public Result queryCommissionStatistics(OrderCommissionStatisticsBO bo) {
        String price = iOrderCommissionStatisticsService.queryCommissionStatistics(bo);
        return new Result<>(price);
    }

    @PostMapping(value = "/queryCategoryMoney")
    @ApiOperation(value = "后台管理系统各类目佣金统计", notes = "后台管理系统各类目佣金统计")
    public Result queryCategoryMoney(OrderCommissionStatisticsBO bo) {
        Page<OrderCommissionVO> page = iOrderCommissionStatisticsService.queryNew(bo);
        return new Result<>(page);
    }

    @PostMapping(value = "/queryShopCommission")
    @ApiOperation(value = "后台管理系统各店铺佣金统计", notes = "后台管理系统各店铺佣金统计")
    public Result queryShopCommission(OrderCommissionStatisticsBO bo) {
        Page<OrderCommissionVO> page = iOrderCommissionStatisticsService.queryShopCommission(bo);
        return new Result<>(page);
    }

    @GetMapping(value = "/exportCategoryMoney")
    @ApiOperation(value = "各类目佣金统计导出", notes = "各类目佣金统计导出")
    public void exportCategoryMoney(HttpServletResponse response, String startTime, String endTime) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"类目编号", "店铺编号", "类目名称", "佣金金额", "店铺类型", "店铺名称"};
        //查询数据
        OrderCommissionStatisticsBO bo = new OrderCommissionStatisticsBO();
        bo.setPageNo(1);
        bo.setPageSize(1000);
        if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
            bo.setStartTime(startTime);
            bo.setEndTime(endTime);
        }
        Page<OrderCommissionVO> page = iOrderCommissionStatisticsService.queryNew(bo);
        List<OrderCommissionVO> list = page.getRecords();
        ExcelExport2.export(response, list, attributeNames, "_各类目佣金统计");
    }

    @GetMapping(value = "/exportShopCommission")
    @ApiOperation(value = "各店铺佣金统计导出", notes = "各店铺佣金统计导出")
    public void exportShopCommission(HttpServletResponse response, String startTime, String endTime) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"类目编号", "店铺编号", "类目名称", "佣金金额", "店铺类型", "店铺名称"};
        //查询数据
        OrderCommissionStatisticsBO bo = new OrderCommissionStatisticsBO();
        bo.setPageNo(1);
        bo.setPageSize(1000);
        if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
            bo.setStartTime(startTime);
            bo.setEndTime(endTime);
        }
        Page<OrderCommissionVO> page = iOrderCommissionStatisticsService.queryShopCommission(bo);
        List<OrderCommissionVO> list = page.getRecords();
        ExcelExport2.export(response, list, attributeNames, "_各店铺佣金统计");
    }
}
